package mvp.com.bbc.rcjavaretrofitdaggermvp.presenter;

import android.net.Network;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import mvp.com.bbc.rcjavaretrofitdaggermvp.app.contact.InfoContact;
import mvp.com.bbc.rcjavaretrofitdaggermvp.app.utils.NetWorkStateUtil;
import mvp.com.bbc.rcjavaretrofitdaggermvp.app.utils.NetworkUtil;
import mvp.com.bbc.rcjavaretrofitdaggermvp.bean.InfoBean;
import mvp.com.bbc.rcjavaretrofitdaggermvp.model.InfoMode;

/**
 * Created by ${cbf} on 2017/11/24.
 */

public class InfoPresenter implements InfoContact.InfoPresenter {
    private InfoContact.InfoMode infoMode;
    private InfoContact.InfoView infoView;

    @Inject
    public InfoPresenter(InfoContact.InfoView infoView) {
        this.infoView = infoView;
        this.infoMode = new InfoMode();
    }

    @Override
    public void infoPresenter(String type, String page, String limit) {
        infoMode.infoMode(type, page, limit)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Observer<List<InfoBean>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull List<InfoBean> infoBeen) {
                        infoView.infoView(infoBeen);

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        NetworkUtil.onError();

                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    @Override
    public void InfoMyQAPresenter(String type, String page, String limit, String userid) {
        infoMode.infoMyQAMode(type, page, limit, userid)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Observer<List<InfoBean>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull List<InfoBean> infoBeen) {
                        infoView.infoView(infoBeen);

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        NetworkUtil.onError();

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
